package org.dandsoft.blackbox.util.list;

/**
 * User: dvilyuzhanin
 * Date: 20.01.2009 1:07:29
 */
public class EntryList<Type> {
    private Entry<Type> first;

    public synchronized void add(Entry<Type> entry) {
        if (first == null) {
            first = entry;
        } else {
            entry.connectAfter(first);
            first = entry;
        }
    }

    public synchronized Entry<Type> next() {
        if (first != null) {
            Entry<Type> result = first;
            first = result.getNext();
            result.disconnect();
            return result;
        } else {
            return null;
        }
    }

    public Type nextObject() {
        Entry<Type> entry = next();
        if (entry != null) {
            return entry.getObject();
        } else {
            return null;
        }
    }
}
